import {
  getDeptRequest,
  deteleDeptRequest,
  addDeptRequest,
  editDeptRequest
} from '@/service/dept/dept.js'
export default {
  state: {
    deptList: []
  },
  mutations: {
    changeDept(state, dept) {
      state.deptList = dept
    }
  },
  actions: {
    async requestDept({ commit }) {
      const deptRes = await getDeptRequest()
      commit('changeDept', deptRes)
    },
    async addRequestDept({ dispatch, commit }, data) {
      await addDeptRequest(data)
      dispatch('requestDept')
    },
    async deteleRequestDept({ dispatch, commit }, dId) {
      await deteleDeptRequest({
        dId
      })
      dispatch('requestDept')
    },
    async EditRequestDept({ dispatch, commit }, data) {
      await editDeptRequest(data)
      dispatch('requestDept')
    }
  }
}
